/*
 *  sphere.h
 *  Ray Tracer
 *
 *  Created by Chirantan Ekbote on 10/6/10.
 *  Copyright 2010 Ohio State University. All rights reserved.
 *
 */

#ifndef _SPHERE_H_
#define _SPHERE_H_

#ifdef  __cplusplus
extern "C" {
#endif	// __cplusplus
	
#include <math.h>
#include "param.h"
#include "vec3.h"
#include "rgb.h"
#include "ray.h"
#include "light.h"
	
struct object;		// Forward declaration of object to avoid compiler errors

typedef struct sphere {
	vec3 center;
	rgb ambientColor;
	rgb diffuseColor;
	float shininess;
	float transparency;
	float radius;
	float refractIndex;
	float r0;
	int useTexture;
} sphere;

static inline sphere makeSphere(const vec3 p, const rgb a, const rgb d, const float s,
								const float t, const float r, const float refractIndex,
								const int useTexture) {
	sphere temp = {p, a, d, s, t, r, refractIndex, 
		(pow(refractIndex - 1, 2) / pow(refractIndex + 1, 2)), useTexture};
	return temp;
}

// Returns 0 if miss, 1 if hit and stores time in t
int sphereHit(const sphere* sp, const ray* r, double* t);

rgb sphereOnHit(const sphere* sp, const ray* r, const vec3 hitPos, const struct object* shapes,
				const light* lights, int depth, const param* p);
	
#ifdef  __cplusplus
}
#endif	// __cplusplus
#endif // _SPHERE_H_